/**
 * 全局公共函数
 *
 * @author jinguangguo & luzhaoman
 * @date 2012.9
 */

String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//提示框
function showTips(str, callback) {
    
    var $dom = $('<div class="tips-box" id="tipsBox">\
                   <div class="tips-wrapper">\
                        <div class="tips-item clearfix">\
                            <span class="tip-img"></span>\
                            <span class="tip-info"></span>\
                        </div>\
                        <div class="tips-confirm">\
                            <a href="javascript:void(0)" class="tips-btn ___closeBox">确定</a>\
                        </div>\
                    </div>\
                </div>');
    
    $dom.find('.tip-info').html(str);
    
    $.XYTipsWindow({
        ___title:"中奖提示框",
        ___content:"text:" + $dom.html(),
        ___showbg:true,
        ___drag:"___boxTitle",
        ___width:"400px",
        ___height:"200px",
        ___boxWrapBdColor:"#666",
        ___boxBdColor:"#a5a5a5",
        ___fnClose:function(){
            //关闭窗口后执行的函数
            if (typeof callback === 'function') {
                callback();
            }
        }
    });
    
}

//检查字符数目
function getStrWithLength(str, num) {
    var count = 0,
        resStr = '',
        tempChar;
    
    for (var i = 0; i < str.length; i++) {
        tempChar = str.charAt(i);
        if (/^[\u0391-\uFFE5]+$/.test(tempChar)) {
            count += 2;
            if (count > num) {
                return resStr;
            }
        } else {
            count++;
            if (count > num) {
                return resStr;
            }
        }
        resStr += tempChar;
    }
    return resStr;
}

//登陆验证
function qbCheckLogin(callback) {
    // 判断是否已登录
    PassportSC.parsePassportCookie();
    if (typeof(PassportSC.cookie['userid']) == "undefined") {
        showLoginDialog(function(){
            if (typeof callback === 'function') {
                callback();
            }
        });
        return;
    }else{
        if (typeof callback === 'function') {
            callback();
        }
    }
}